import streamlit as st
from webui_pages.utils import *
from streamlit_option_menu import option_menu
from webui_pages.dialogue.dialogue import dialogue_page, chat_box
from webui_pages.knowledge_base.knowledge_base import knowledge_base_page
import os
import sys
from configs import VERSION
from server.utils import api_address


api = ApiRequest(base_url=api_address())

if __name__ == "__main__":
    is_lite = "lite" in sys.argv

    st.set_page_config(
        "AI 问答",
        os.path.join("img", "j-logo.png"),
        initial_sidebar_state="expanded",
        menu_items={
            'Get Help': 'http://baidu.com',
            'Report a bug': "http://baidu.com",
            'About': f"""欢迎使用AI问答  {VERSION}！"""
        }
    )
    st.markdown('<style> .st-emotion-cache-janbn0{background-color: #1A2A3D !important; }  </style>', unsafe_allow_html=True)
    # st.markdown('<style>.menu .container-xxl{background-color:#313F50 !important;}.element-container:nth-child(5){display:none;}.element-container:nth-child(6){display:none;}.element-container:nth-child(7){display:none;}.element-container:nth-child(8){display:none;}.element-container:nth-child(9){display:none;}.element-container:nth-child(10){display:none;}.element-container:nth-child(11){display:none;}.element-container:nth-child(12){display:none;}button[data-testid="baseButton-secondary2"]{display:none;}<style>', unsafe_allow_html=True)
    st.markdown('<style>button[data-testid="baseButton-secondary2"]{display:none;}</style>', unsafe_allow_html=True)
    st.markdown('''<style>.stMarkdown p{font-size: 14px;} .assat-txt{font-size: 14px;margin: 0px 0px 6pt;}.menu-btn ul.bt-list li{display:inline-block;list-style:none;margin:0.9em 0;}.menu-btn ul.bt-list li a{font-size: 14px;margin-right: 0.6em;border-radius: 0.21em;}.menu-btn a.hvr-fade{background:#133d51 !important;color:#e5f4ff;}.menu-btn a.button,a.button2{padding:0.4em;cursor:pointer;background:none;text-decoration:none;-webkit-tap-highlight-color:rgba(0,0,0,0);}.menu-btn a.hvr-fade:hover,a.hvr-fade:focus,a.hvr-fade:active{background-color:#2a5e77 !important;color:white;}@media (max-width: 768px) {section[data-testid*='stSidebar']{display:none}}button[kind="headerNoPadding"]{display:none;}</style>
<div class="menu-btn">
        <div class="asst-icon" style="margin-top: 0.5em;float: left;">
		<?xml version="1.0" encoding="UTF-8" standalone="no"?>
        <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
        <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="36" height="36" viewBox="0 0 36 36" enable-background="new 0 0 36 36" xml:space="preserve">  <image id="image0" width="36" height="36" x="0" y="0"
            href="" ></image>
        </svg>
	</div>
		<div class="message-assat" style="margin-left: 3em;margin-top: -1.5em;float: left;">
		 <p class="assat-txt">您好，我是你的军事AI助手</p><p class="assat-txt">作为你的军事AI助手，我可以帮助你高效完成只会协同工作，你可以试着问我:</p>
	     <ul class="bt-list">
			<li>
				<a href="#" class="hvr-fade button cxtq">查询天气</a>
				<a href="#" class="hvr-fade button ghlj">规划路径</a>
				<a href="#" class="hvr-fade button tjbj">添加标记</a>
				<a href="#" class="hvr-fade button hjlxr">呼叫联系人</a>
			</li>		
		</ul>
		</div>
	</div>
	''', unsafe_allow_html=True)
    pages = {
        "对话": {
            "icon": "chat",
            "func": dialogue_page,
        }
        # ,
        # "知识库管理": {
        #     "icon": "hdd-stack",
        #     "func": knowledge_base_page,
        # },
    }

    with st.sidebar:
        st.image(
            os.path.join(
                "img",
                "j-logo.png"
            ),
            use_column_width=True
        )
        st.caption(
            f"""<p align="right">当前版本：{VERSION}</p>""",
            unsafe_allow_html=True,
        )
        st.markdown('<style>::-webkit-scrollbar-track {background-color: #273648;}</style>', unsafe_allow_html=True)
        options = list(pages)
        icons = [x["icon"] for x in pages.values()]

        default_index = 0
        selected_page = option_menu(
            "",
            options=options,
            icons=icons,
            # menu_icon="chat-quote",
            default_index=default_index,
        )

    if selected_page in pages:
        pages[selected_page]["func"](api=api, is_lite=is_lite)
